<template>
  <el-table
    :data="tableData"
    style="width: 100%">
    <el-table-column
      label="活动ID"
      width="180">
      <template slot-scope="scope">
        {{ scope.row._id }}
      </template>
    </el-table-column>
    <el-table-column
      label="活动名称"
      width="180">
      <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{ scope.row.title }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="简介"
      width="180">
      <template slot-scope="scope">
        {{scope.row.intro}}
      </template>
    </el-table-column>
    <el-table-column label="活动封面">
      <template slot-scope="scope">
        <!-- {{scope.row.poster}} -->
        <!-- <img :src="scope.row.poster" alt=""> -->
        <el-image 
          style="width: 100px; height: 100px"
          :src="scope.row.poster" 
          :preview-src-list="[scope.row.poster]">
        </el-image>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
  import {activityGet,activityDel} from '../../api/job'
  export default {
    data() {
      return {
        tableData: [{
          _id: '2016-05-02',
          title: '王小虎',
          intro:'简介',
          poster:'img.png'
        }]
      }
    },
    created () {
      activityGet().then(res=>{
        console.log(res);
        this.tableData = res.data.data
      })
    },
    methods: {
      handleEdit(index, row) {
        console.log(index, row);
      },
      handleDelete(index, row) {
        console.log(index, row);
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          activityDel(row._id).then(res=>{ //删除线上
            console.log(res);
            if(res.data.code==1){
              this.tableData.splice(index,1) //更新本地列表
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
            }
          })
        })
      }
    }
  }
</script>